<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>SunCMS 后台管理系统</title>
<link href="./images/system/style.css" rel="stylesheet" type="text/css">
<script src="./include/javascript/jquery.js" type="text/javascript"></script>
<script src="./include/javascript/json.js" type="text/javascript"></script>
<script src="./include/javascript/main.js" type="text/javascript"></script>
<script type="text/javascript">
	var SCRIPT='<?php echo SCRIPT_NAME?>';
	var SITE_URL='<?php echo SITE_URL?>';

	var newCat = {
		_saving: false,
		_old: '时政要闻|szyw\n经济观察|jjgc\n  股市风云|gsfy\n  地产信息|dcxx\n信息产业|xxcy\n  应用软件|yyrj\n  游戏产业|yxcy',
		save: function()
		{
			if(this._saving==true) return false;
			if(global.tabId==1){if(!app.categoryCheck()) return false;}
			else
			{
				var name = this._format($("#betch_data").val());
				if(name==''||this._old==name)
				{
					parent.dialog.alert('请填写栏目名称（更改示例内容）！');
					return false;
				}
				var catName = this._checkAndMakeArray(name)
				if(catName==false) return false;
			}
			this._saving = true;
			$("#ajaxing").show();
			if(global.tabId==1) 
			{
				var contentData = {
					'pid':$("#pid").val(),
					'name':$.trim($("#name").val()),
					'dir':$.trim($("#dir").val()),
					'images':$("#thumb").val(),
					'keywords':$.trim($("#keywords").val()),
					'description':$.trim($("#description").val()),
					'index_temp':$("#index_temp").val(),
					'list_temp':$("#list_temp").val(),
					'detail_temp':$("#detail_temp").val(),
					'list_rule':$.trim($("#list_rule").val()),
					'detail_rule':$.trim($("#detail_rule").val()),
					'workflow_id':$("#workflow_id").val(),
					'list_no':$.trim($("#list_no").val()),
					'order':$.trim($("#order").val()),
					'ifshow':$("#openshow_yes").attr('checked')==true?1:0,
					'onepage':$("#onepage_yes").attr('checked')==true?1:0,
					'post':$("#post_yes").attr('checked')==true?1:0,
					'post_group_ids':$("#post_group_ids").val(),
					'attribute_extend':$("#attribute_extend").val(),
					'model':$("#model").val()
				};
			}
			else
			{
				var contentData = {
					'pid':$("#pid").val(),
					'name':catName,
					'model':$("#model").val(),
					'index_temp':$("#index_temp2").val(),
					'list_temp':$("#list_temp2").val(),
					'detail_temp':$("#detail_temp2").val(),
					'list_rule':$.trim($("#list_rule2").val()),
					'detail_rule':$.trim($("#detail_rule2").val())
				};
			}
			$.ajax({
				url: SITE_URL+SCRIPT+"?m=document&a=category&do=add",
				data: {'data':JSON.stringify(contentData),'type':global.tabId},
				error: function (xmlHttpRequest, error) {
					newCat._saving = false;
					$("#ajaxing").hide();
					parent.dialog.alert('AJAX数据获取异常！');
				},
				success: function(rs)
				{
					if(rs==1)
					{
						parent.frames[0].catMag.getCategoryMenu();
						parent.dialog.alert('栏目新建成功！',1);
					}
					else
					{
						parent.dialog.alert('栏目新建失败！');
					}
					window.setTimeout('$("#ajaxing").hide();',300);
					newCat._saving = false;
				}
			});
		},
		_format: function(str)
		{
			/** todo: 格式化,去掉左边空格,右边空格,空字符(换行符除外) **/
			str=$.trim(str);
			str=str.replace(/[\t\r\f]/g,'');
			str=str.replace(/[ \t\r\f]*\n[ \t\r\f]*\n+/g,'\n');
			return str;
		},
		_checkAndMakeArray: function(str)
		{
			var reg=/([ ]{2})*\S+/g;
			var arr=str.match(reg);
			if(arr.length>0)
			{
				var newArr = {};
				var first = arr[0];
				var sp = false;
				for(var x=0;x<first.length;x++){if(first.charAt(x)==' '){parent.dialog.alert('第1行格式错误！');return false;}else if(first.charAt(x)=='|'){sp = true;}}
				if(sp==false){parent.dialog.alert('第1行格式错误：栏目目录未填写！');return false;}
				else
				{
					var firstArr = first.split('|');
					if(firstArr[1].match(/^[A-Za-z0-9_-]{2,10}$/)==null)
					{
						parent.dialog.alert('第1行格式错误：请输入长度在2-10位之间的字符的栏目目录！');
						return false;
					}
					else
					{
						newArr[0] = {'name':firstArr[0],'dir':firstArr[1]};
						sp = false;
					}
				}
				var previous=0;
				for(var i=1;i<arr.length;i++)
				{
					var cur=arr[i];
					var count2=0;

					for(var j=0;j<cur.length;j++)
					{
						if(cur.charAt(j)=='|') 
						{
							sp = true;
							if(count2==0) break;
						}
						else if(cur.charAt(j)==' '){count2++;}
					}
					if(count2%2!=0)
					{
						parent.dialog.alert("第"+(i+1)+"行格式错误");
						return false;
					}
					count2=count2/2;
					if(Math.abs(previous-count2)>1)
					{
						parent.dialog.alert("第"+(i+1)+"行格式错误！");
						return false;
					}
					if(sp==false)
					{
						parent.dialog.alert('第'+(i+1)+'行格式错误：栏目目录未填写！');
						return false;
					}
					else
					{
						var curArr = cur.split('|');
						if(curArr[1].match(/^[A-Za-z0-9_-]{2,10}$/i)==null)
						{
							parent.dialog.alert('第'+(i+1)+'行格式错误：栏目目录格式错误！');
							return false;
						}
						else
						{
							newArr[i] = {'name':curArr[0],'dir':curArr[1]};
							sp = false;
						}
					}
					previous=count2;
				}
			}
			return newArr;
		}
	}
</script>
</head>
<body>
<input type="hidden" id='pid' value='<?php echo $datas['id']; ?>'>
<input type="hidden" id='model' value='<?php echo $datas['model']; ?>'>
<div class="main">
<div class='main_left'>
<div class='main_right'>
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tbody>
<tr>
<td valign="top">
	<div class='nav_info'>
		<div class='info category_attribute' onclick='global.tab(1);'><img src="./images/system/icon/34.gif"/><b>新建栏目</b></div>
		<div class='info2 category_attribute' onclick='global.tab(2);'><img src="./images/system/icon/34.gif"/><b>批量新建</b></div>
	</div>
</td>
</tr>
<tr>
<td valign="top">
	<div style='padding:5px;' id='stab_1'>
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
		<tbody>
		<tr>
		<td width='50%;' valign='top' style='padding-right:5px;'>
			<fieldset>
				<legend> 基本属性 </legend>
				<table width="100%">
					<tbody>
					<tr>
						<td align="right">栏目名称：</td>
						<td align="left">
							<input type="text" id='name' class='sinput tp7' /><span style="color: red; padding-left: 2px; padding-top: 13px;">*</span>
						</td>
					</tr>
					<tr>
						<td align="right">栏目目录：</td>
						<td align="left">
							<input type="text" id='dir' class='sinput tp7' /><span style="color: red; padding-left: 2px; padding-top: 13px;">*</span>
						</td>
					</tr>
					<tr>
					  <td  align="right" >栏目引导图：</td>
					  <td>
						  <input id='' type="text" id="thumb_pic" class='sinput tp7' />
						  <a class="slbutton" href="javascript:void(0);" onclick="global.thumbUpload(2);"><input type="button" class="srbutton" value="上传"/></a>
					  </td>
					</tr>
					<tr>
						<td align="right">栏目关键词：</td>
						<td align="left">
							<input type="text" size="40" id='keywords' class='sinput tp7' />
						</td>
					</tr>
					<tr>
					  <td  align="right" valign='top' style='padding-top:3px;'>栏目描述：</td>
					  <td  >
						<textarea style='width:220px;margin-top:3px;' id='description'></textarea>
					  </td>
					</tr>
					<tr>
						<td align="right">是否单页栏目：</td>
						<td align="left">
							<input type="radio"  id='onepage_yes' value='1'/>是
							<input type="radio" checked  id='onepage_no'  value='0'/>否
						</td>
					</tr>
				</tbody>
				</table>
			</fieldset>
			<fieldset style='margin-top:10px;*margin-top:5px;'>
				<legend> 投稿设置 </legend>
				<table width="100%">
					<tbody>
						<tr>
							<td align='right' width="30%">是否允许投稿：</td>
							<td>
								<input type="radio" name="ifpost" id='post_yes' checked value='1'>是
								<input type="radio" name="ifpost" id='post_no' value='0'>否
							</td>
						</tr>
						<tr>
							<td align='right'>允许投稿会员组：</td>
							<td>
								<input type="text" id='post_group_ids' class="sinput tp7" readonly />
								<a class="slbutton" href="javascript:void(0);" onclick="catMag.getPostGroup();"><input type="button" class="srbutton" value="..."/></a>
							</td>
						</tr>
					</tbody>
				</table>
			</fieldset>
			</td>
			<td valign="top" style='padding-left:5px;' width='50%'>
			<fieldset>
				<legend>模板及命名 </legend>
				<table width="100%">
					<tbody>
					<tr>
						<td align="right">首页模板：</td>
						<td align="left">
							<input type="text" id= 'index_temp' value="<?php if($datas['attribute_extend']){echo $datas['index_temp'];} ?>" class='sinput tp7' /> 
							<a class="slbutton" href="javascript:void(0);" onclick=""><input type="button" class="srbutton" value="..."/></a>
						</td>
					</tr>
					<tr>
						<td align="right" width="30%">列表页模板：</td>
						<td align="left">
							<input type="text" id= 'list_temp' value="<?php if($datas['attribute_extend']){echo $datas['list_temp'];}else{echo 'list.html';} ?>" class='sinput tp7' />
							<a class="slbutton" href="javascript:void(0);" onclick=""><input type="button" class="srbutton" value="..."/></a>
						</td>
					</tr>
					<tr>
						<td align="right">详细页模板：</td>
						<td align="left">
							<input type="text" value="<?php if($datas['attribute_extend']){echo $datas['detail_temp'];}else{echo 'detail.html';} ?>" id="detail_temp" class='sinput tp7' /> 
							<a class="slbutton" href="javascript:void(0);" onclick=""><input type="button" class="srbutton" value="..."/></a>
						</td>
					</tr>
					<tr>
						<td  align="right" nowrap>列表页命名规则：</td>
						<td  align="left">
							<input type="text" class='sinput' style='width:225px;' id="list_rule" value="<?php if($datas['attribute_extend']){echo $datas['list_rule'];}else{echo '/${categorypath}/list-${page.id}.html';} ?>" size="30"/>
						</td>
					</tr>
					<tr>
						<td align="right">详细页命名规则：</td>
						<td align="left">
							<input type="text" value="<?php if($datas['attribute_extend']){echo $datas['detail_rule'];}else{echo '/${categorypath}/${document.id}.html';} ?>" id="detail_rule" class='sinput'  style='width:225px;'/>
						</td>
					</tr>
				</tbody>
				</table>
			</fieldset>
			<fieldset style='margin-top:10px;*margin-top:5px;'>
				<legend>扩展属性 </legend>
				<table width="100%" style="margin: 3px auto;">
					<tbody>
					<tr>
						<td align="right">是否开放显示：</td>
						<td align="left">
							<input type="radio" name='ifopen'  id='openshow_yes' checked value='1' />是
							<input type="radio" name='ifopen'  id='openshow_no' value='0'/>否
						</td>
					</tr>
					<tr>
						<td align="right" width="30%">排序权值：</td>
						<td align="left" width="69%">
							<input type="text" id='order'  class='sinput tp7' />
						</td>
					</tr>
					<tr>
						<td nowrap="" align="right">列表页项目数：</td>
						<td align="left">
							<input type="text" id='list_no' value="<?php if($datas['attribute_extend']){echo $datas['list_no'];}else{echo '15';} ?>" class='sinput tp7' />
						</td>
					</tr>
					<tr>
						<td align='right'>工作流：</td>
						<td>
							<input type="text" id='workflow_id' class="sinput tp7" value="<?php if($datas['attribute_extend']){echo $datas['workflow_id'];} ?>" readonly />
							<a class="slbutton" href="javascript:void(0);" onclick=""><input type="button" class="srbutton" value="..."/></a>
						</td>
					</tr>
					<tr>
						<td width="13%" align='right'>属性沿用：</td>
						<td>
							<select id='attribute_extend' class='sinput tp7'>
								<option value='0'>仅本栏目
								<option value='1'>所有子栏目
							</select>
						</td>
					</tr>
				</tbody>
				</table>
			</fieldset>
			</td>
		</tr>
		</tbody>
		</table>
	</div>
	<div style='display:none;padding:5px;' id='stab_2'>
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
		<tbody>
		<tr>
		<td width='50%;' valign='top' style='padding-right:5px;'>
			<fieldset>
				<legend> 示例 </legend>
				<table width="100%">
					<tbody>
					<tr>
					  <td width='10%'>&nbsp;</td>
					  <td  >
<textarea style='width:280px;height:280px;margin-top:3px;' id='betch_data'>时政要闻|szyw
经济观察|jjgc
  股市风云|gsfy
  地产信息|dcxx
信息产业|xxcy
  应用软件|yyrj
  游戏产业|yxcy</textarea>
					  </td>
					  <td width='10%'>&nbsp;</td>
					</tr>
				</tbody>
				</table>
			</fieldset>
			</td>
			<td valign='top' style='padding-left:5px;'>
			<fieldset>
				<legend>新建要求 </legend>
				<table width="100%">
					<tbody>
					<tr>
					  <td  style='padding-left:20px;'>
						1.每行一个栏目。<br>
						2.栏目名和栏目目录之间用‘|’分隔。<br>
						3.不能有空行。<br>
						4.子栏目相对父栏目使用两个英文空格缩进。<br>
						5.批量新建目前只支持一级子栏目。<br>
						6.您可以在示例中直接更改内容。
					  </td>
					</tr>
				</tbody>
				</table>
			</fieldset>
			<fieldset style='margin-top:10px;*margin-top:5px;'>
				<legend>模板及命名 </legend>
				<table width="100%">
					<tbody>
					<tr>
						<td align="right">首页模板：</td>
						<td align="left">
							<input type="text" id= 'index_temp2' value="<?php if($datas['attribute_extend']){echo $datas['index_temp'];} ?>" class='sinput tp7' /> 
							<a class="slbutton" href="javascript:void(0);" onclick=""><input type="button" class="srbutton" value="..."/></a>
						</td>
					</tr>
					<tr>
						<td align="right" width="30%">列表页模板：</td>
						<td align="left">
							<input type="text" id= 'list_temp2' value="<?php if($datas['attribute_extend']){echo $datas['list_temp'];}else{echo 'list.html';} ?>" class='sinput tp7' />
							<a class="slbutton" href="javascript:void(0);" onclick=""><input type="button" class="srbutton" value="..."/></a>
						</td>
					</tr>
					<tr>
						<td align="right">详细页模板：</td>
						<td align="left">
							<input type="text" value="<?php if($datas['attribute_extend']){echo $datas['detail_temp'];}else{echo 'detail.html';} ?>" id="detail_temp2" class='sinput tp7' /> 
							<a class="slbutton" href="javascript:void(0);" onclick=""><input type="button" class="srbutton" value="..."/></a>
						</td>
					</tr>
					<tr>
						<td  align="right" nowrap>列表页命名规则：</td>
						<td  align="left">
							<input type="text" class='sinput' style='width:225px;' id="list_rule2" value="<?php if($datas['attribute_extend']){echo $datas['list_rule'];}else{echo '/${categorypath}/list-${page.id}.html';} ?>" size="30"/>
						</td>
					</tr>
					<tr>
						<td align="right">详细页命名规则：</td>
						<td align="left">
							<input type="text" value="<?php if($datas['attribute_extend']){echo $datas['detail_rule'];}else{echo '/${categorypath}/${document.id}.html';} ?>" id="detail_rule2" class='sinput'  style='width:225px;'/>
						</td>
					</tr>
				</tbody>
				</table>
			</fieldset>
			</td>
		</tr>
		</tbody>
		</table>
	</div>
</td>
</tr>
</tbody>
</table>
</div><!--/main_right-->
</div><!--/main_left-->
</div><!--/main-->
<div id="ajaxing" style="padding-top: 5px; background-color: #FFFFCC; position: absolute; z-index: 801; height: 20px; width: 120px; top: 60px;*top:63px; left: 21px;display:none;">
	<img src="./images/system/icon/67.gif"/><font style='color:#008000;' id='ajax_msg'> 正在保存......　</font>
</div>
<input type="submit" style='display:none;' id="sbt" onclick='newCat.save();'>
</body>
</html>
